package com.abhimanyu.bootstrap.writers;

import java.util.List;

import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.abhimanyu.messaging.IMessageSender;
import com.abhimanyu.messaging.model.IMessage;

@Component
public class DollarRateNotifierTextMessageWriter implements
		ItemWriter<IMessage> {
	
	@Autowired
	private IMessageSender messageSender;

	public void write(List<? extends IMessage> messages) throws Exception {
		System.out
				.println("************************************************SENDING FOLLOWING MESSAGES ************************************************");
		System.out.println(messages);
		sendMessages(messages);
	}

	private void sendMessages(List<? extends IMessage> messages) {
		for (IMessage message : messages) {
			messageSender.sendMessage(message);
		}
	}

	public void setMessageSender(IMessageSender messageSender) {
		this.messageSender = messageSender;
	}

}
